Overview | Package | Class | Tree | Deprecated | Index | Help Java Platform
1.1.7
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Class com.sun.java.swing.JSlider

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--com.sun.java.swing.JComponent
                    |
                    +--com.sun.java.swing.JSlider

public class JSlider
extends JComponent
implements SwingConstants, Accessible
A component that lets the user graphically select a value by slding a knob within a bounded interval. The slider can show both major tick marks and minor tick marks between them. The number of pixels between the tick marks is controlled with setMajorTickSpacing and setMinorTickSpacing.

For the keyboard keys used by this component in the standard Look and Feel (L&F) renditions, see the JSlider key assignments.

Warning: serialized objects of this class will not be compatible with future swing releases. The current serialization support is appropriate for short term storage or RMI between Swing1.0 applications. It will not be possible to load serialized Swing1.0 objects with future releases of Swing. The JDK1.2 release of Swing will be the compatibility baseline for the serialized form of Swing objects.

See Also:
Serialized Form

Inner Class Summary
JSlider.AccessibleJSlider
          The class used to obtain the accessible role for this object.
 
Inner classes inherited from class com.sun.java.swing.JComponent
JComponent.AccessibleJComponent
 
Field Summary
ChangeEvent changeEvent
          Only one ChangeEvent is needed per slider instance since the event's only (read-only) state is the source property.
ChangeListener changeListener
          The changeListener (no suffix) is the listener we add to the Sliders model.
int majorTickSpacing
          The number of pixels between the major tick marks -- the larger marks that break up the minor tick marks.
int minorTickSpacing
          The number of pixels between the minor tick marks -- the smaller marks that occur between the major tick marks.
int orientation
           
BoundedRangeModel sliderModel
          The data model that handles the numeric maximum value, minimum value, and current-position value for the slider.
boolean snapToTicks
          If true, the knob (and the data value it represents) resolve to the closest tick mark next to where the user positioned the knob.
 
Fields inherited from class com.sun.java.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
JSlider(int orientation, int min, int max, int value)
          Creates a slider with the specified orientation and the specified mimimum, maximum, and initial values.
JSlider()
          Creates a horizontal slider with the range 0 to 100 and an intitial value of 50.
 
Method Summary
void addChangeListener(ChangeListener l)
          Adds a ChangeListener to the slider.
ChangeListener createChangeListener()
          Subclasses that want to handle model ChangeEvents differently can override this method to return their own ChangeListener implementation.
java.util.Hashtable createStandardLabels(int increment)
          Creates a hashtable that will draw text labels starting at the slider minimum using the increment specified.
java.util.Hashtable createStandardLabels(int increment, int start)
          Creates a hashtable that will draw text labels starting at the start point specified using the increment specified.
void fireStateChanged()
          Send a ChangeEvent, whose source is this Slider, to each listener.
AccessibleContext getAccessibleContext()
          Get the AccessibleContext associated with this JComponent
int getExtent()
           
boolean getInverted()
          Returns true if the value-range shown for the slider is reversed, with the maximum value at the left end of a horizontal slider or at the bottom of a vertical one.
java.util.Dictionary getLabelTable()
          Returns the dictionary of what labels to draw at which values.
int getMajorTickSpacing()
           
int getMaximum()
          Returns the maximum value supported by the slider.
int getMinimum()
          Returns the minimum value supported by the slider.
int getMinorTickSpacing()
           
BoundedRangeModel getModel()
          Returns data model that handles the sliders three fundamental properties: minimum, maximum, value.
int getOrientation()
           
boolean getPaintLabels()
           
boolean getPaintTicks()
           
boolean getSnapToTicks()
          Returns true if the knob (and the data value it represents) resolve to the closest tick mark next to where the user positioned the knob.
java.lang.String getUIClassID()
          Returns the name of the L&F class that renders this component.
com.sun.java.swing.plaf.SliderUI getUI()
          Gets the UI object which implements the L&F for this component.
boolean getValueIsAdjusting()
          True if the slider knob is being dragged.
int getValue()
          Returns the sliders value.
void removeChangeListener(ChangeListener l)
          Removes a ChangeListener from the slider.
void setExtent(int extent)
          Sets the size of the range "covered" by the knob.
void setInverted(boolean b)
          Specify true to reverse the value-range shown for the slider so that the maximum value is at the left end of a horizontal slider or at the bottom of a vertical one.
void setLabelTable(java.util.Dictionary labels)
          Used to specify what label will be drawn at any given value.
void setMajorTickSpacing(int n)
          Sets the number of pixels between major tick marks.
void setMaximum(int maximum)
          Sets the models maximum property.
void setMinimum(int minimum)
          Sets the models minimum property.
void setMinorTickSpacing(int n)
          Sets the number of pixels between minor tick marks.
void setModel(BoundedRangeModel newModel)
          Sets the model that handles the sliders three fundamental properties: minimum, maximum, value.
void setOrientation(int orientation)
          Set the scrollbars orientation to either VERTICAL or HORIZONTAL.
void setPaintLabels(boolean b)
          Determines whether labels are painted on the slider.
void setPaintTicks(boolean b)
          Determines whether tick marks are painted on the slider.
void setSnapToTicks(boolean b)
          Specifying true makes the knob (and the data value it represents) resolve to the closest tick mark next to where the user positioned the knob.
void setUI(com.sun.java.swing.plaf.SliderUI ui)
          Sets the UI object which implements the L&F for this component.
void setValueIsAdjusting(boolean b)
          Sets the models valueIsAdjusting property.
void setValue(int n)
          Sets the sliders current value.
java.lang.String toString()
          Returns a string containing that displays and identifies this object's propeties.
void updateLabelUIs()
          Called internally to replace the label UIs with the latest versions from the UIFactory when the UIFactory notifies us via updateUI that the L&F has changed.
void updateUI()
          Notification from the UIFactory that the L&F has changed.
 
Methods inherited from class com.sun.java.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getUIClassID, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paint, processComponentKeyEvent, processFocusEvent, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setBounds, setDebugGraphicsOptions, setDoubleBuffered, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addNotify, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponentAt, getComponentAt, getComponent, getComponentCount, getComponents, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, paint, paramString, preferredSize, printComponents, print, processContainerEvent, processEvent, removeAll, remove, remove, removeContainerListener, removeNotify, setLayout, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getName, getParent, getPeer, getPreferredSize, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paint, paramString, postEvent, preferredSize, prepareImage, prepareImage, printAll, print, processComponentEvent, processEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait
 

Field Detail

sliderModel

protected BoundedRangeModel sliderModel
The data model that handles the numeric maximum value, minimum value, and current-position value for the slider.

majorTickSpacing

protected int majorTickSpacing
The number of pixels between the major tick marks -- the larger marks that break up the minor tick marks.

minorTickSpacing

protected int minorTickSpacing
The number of pixels between the minor tick marks -- the smaller marks that occur between the major tick marks.
See Also:
setMinorTickSpacing

snapToTicks

protected boolean snapToTicks
If true, the knob (and the data value it represents) resolve to the closest tick mark next to where the user positioned the knob.
See Also:
setSnapToTicks

orientation

protected int orientation
See Also:
setOrientation

changeListener

protected ChangeListener changeListener
The changeListener (no suffix) is the listener we add to the Sliders model. By default this listener just forwards events to ChangeListeners (if any) added directly to the slider.
See Also:
addChangeListener, createChangeListener

changeEvent

protected transient ChangeEvent changeEvent
Only one ChangeEvent is needed per slider instance since the event's only (read-only) state is the source property. The source of events generated here is always "this". The event is lazily created the first time that an event notification is fired.
See Also:
fireStateChanged
Constructor Detail

JSlider

public JSlider(int orientation,
               int min,
               int max,
               int value)
Creates a slider with the specified orientation and the specified mimimum, maximum, and initial values.
Throws:
java.lang.IllegalArgumentException - if orientation is not one of VERTICAL, HORIZONTAL
See Also:
setOrientation, setMinimum, setMaximum, setValue

JSlider

public JSlider()
Creates a horizontal slider with the range 0 to 100 and an intitial value of 50.
Method Detail

getUI

public com.sun.java.swing.plaf.SliderUI getUI()
Gets the UI object which implements the L&F for this component.
Returns:
the SliderUI object that implements the Slider L&F

setUI

public void setUI(com.sun.java.swing.plaf.SliderUI ui)
Sets the UI object which implements the L&F for this component.
Parameters:
ui - the SliderUI L&F object
See Also:
getUI

updateUI

public void updateUI()
Notification from the UIFactory that the L&F has changed. Called to replace the UI with the latest version from the default UIFactory.
Overrides:
updateUI in class JComponent
See Also:
updateUI

getUIClassID

public java.lang.String getUIClassID()
Returns the name of the L&F class that renders this component.
Returns:
"SliderUI"
Overrides:
getUIClassID in class JComponent
See Also:
getUIClassID, getUI

createChangeListener

protected ChangeListener createChangeListener()
Subclasses that want to handle model ChangeEvents differently can override this method to return their own ChangeListener implementation. The default ChangeListener just forwards ChangeEvents to the ChangeListeners added directly to the slider.
See Also:
fireStateChanged

addChangeListener

public void addChangeListener(ChangeListener l)
Adds a ChangeListener to the slider.
Parameters:
l - the ChangeListener to add
See Also:
fireStateChanged, removeChangeListener

removeChangeListener

public void removeChangeListener(ChangeListener l)
Removes a ChangeListener from the slider.
Parameters:
l - the ChangeListener to remove
See Also:
fireStateChanged, addChangeListener

fireStateChanged

protected void fireStateChanged()
Send a ChangeEvent, whose source is this Slider, to each listener. This method method is called each time a ChangeEvent is received from the model.
See Also:
addChangeListener, EventListenerList

getModel

public BoundedRangeModel getModel()
Returns data model that handles the sliders three fundamental properties: minimum, maximum, value.
See Also:
setModel

setModel

public void setModel(BoundedRangeModel newModel)
Sets the model that handles the sliders three fundamental properties: minimum, maximum, value.
See Also:
getModel

getValue

public int getValue()
Returns the sliders value.
Returns:
the models value property
See Also:
setValue

setValue

public void setValue(int n)
Sets the sliders current value. This method just forwards the value to the model.
See Also:
getValue

getMinimum

public int getMinimum()
Returns the minimum value supported by the slider.
Returns:
the value of the models minimum property
See Also:
setMinimum

setMinimum

public void setMinimum(int minimum)
Sets the models minimum property.
See Also:
getMinimum, setMinimum

getMaximum

public int getMaximum()
Returns the maximum value supported by the slider.
Returns:
the value of the models maximum property
See Also:
setMaximum

setMaximum

public void setMaximum(int maximum)
Sets the models maximum property.
See Also:
getMaximum, setMaximum

getValueIsAdjusting

public boolean getValueIsAdjusting()
True if the slider knob is being dragged.
Returns:
the value of the models valueIsAdjusting property
See Also:
setValueIsAdjusting

setValueIsAdjusting

public void setValueIsAdjusting(boolean b)
Sets the models valueIsAdjusting property. Slider look and feel implementations should set this property to true when a knob drag begins, and to false when the drag ends. The slider model will not generate ChangeEvents while valueIsAdjusting is true.
See Also:
getValueIsAdjusting, setValueIsAdjusting

getExtent

public int getExtent()
Returns:
the range of values "covered" by the knob.
See Also:
setExtent, getExtent

setExtent

public void setExtent(int extent)
Sets the size of the range "covered" by the knob. Most look and feel implementations will change the value by this amount if the user clicks on either side of the knob.
See Also:
getExtent, setExtent

getOrientation

public int getOrientation()
Returns:
VERTICAL or HORIZONTAL
See Also:
setOrientation

setOrientation

public void setOrientation(int orientation)
Set the scrollbars orientation to either VERTICAL or HORIZONTAL.
Throws:
java.lang.IllegalArgumentException - if orientation is not one of VERTICAL, HORIZONTAL
See Also:
getOrientation

getLabelTable

public java.util.Dictionary getLabelTable()
Returns the dictionary of what labels to draw at which values.
Returns:
the Dictionary containing labels and where to draw them

setLabelTable

public void setLabelTable(java.util.Dictionary labels)
Used to specify what label will be drawn at any given value. The key-value pairs are of this format: { Integer value, java.awt.Component label }
See Also:
createStandardLabels, getLabelTable

updateLabelUIs

protected void updateLabelUIs()
Called internally to replace the label UIs with the latest versions from the UIFactory when the UIFactory notifies us via updateUI that the L&F has changed.
See Also:
updateUI

createStandardLabels

public java.util.Hashtable createStandardLabels(int increment)
Creates a hashtable that will draw text labels starting at the slider minimum using the increment specified. If you call createStandardLabels( 10 ) and the slider minimum is zero, then it will make labels for the values 0, 10, 20, 30, and so on.
See Also:
setLabelTable

createStandardLabels

public java.util.Hashtable createStandardLabels(int increment,
                                      int start)
Creates a hashtable that will draw text labels starting at the start point specified using the increment specified. If you call createStandardLabels( 10, 2 ), then it will make labels for the values 2, 12, 22, 32, and so on.
See Also:
setLabelTable

getInverted

public boolean getInverted()
Returns true if the value-range shown for the slider is reversed, with the maximum value at the left end of a horizontal slider or at the bottom of a vertical one.
Returns:
true if the slider values are reversed from their normal order

setInverted

public void setInverted(boolean b)
Specify true to reverse the value-range shown for the slider so that the maximum value is at the left end of a horizontal slider or at the bottom of a vertical one. Specify false to put the value range in the normal order.
Parameters:
b - true to reverse the slider values from their normal order

getMajorTickSpacing

public int getMajorTickSpacing()
Returns:
the number of pixels between major ticks
See Also:
setMajorTickSpacing

setMajorTickSpacing

public void setMajorTickSpacing(int n)
Sets the number of pixels between major tick marks.
See Also:
getMajorTickSpacing

getMinorTickSpacing

public int getMinorTickSpacing()
Returns:
the number of pixels between minor ticks
See Also:
getMinorTickSpacing

setMinorTickSpacing

public void setMinorTickSpacing(int n)
Sets the number of pixels between minor tick marks.
See Also:
getMinorTickSpacing

getSnapToTicks

public boolean getSnapToTicks()
Returns true if the knob (and the data value it represents) resolve to the closest tick mark next to where the user positioned the knob.
Returns:
true if the value snaps to the nearest tick mark, else false
See Also:
setSnapToTicks

setSnapToTicks

public void setSnapToTicks(boolean b)
Specifying true makes the knob (and the data value it represents) resolve to the closest tick mark next to where the user positioned the knob.
Parameters:
b - true to snap the knob to the nearest tick mark
See Also:
getSnapToTicks

getPaintTicks

public boolean getPaintTicks()
Returns:
true if tick marks are painted, else false
See Also:
setPaintTicks

setPaintTicks

public void setPaintTicks(boolean b)
Determines whether tick marks are painted on the slider.
See Also:
getPaintTicks

getPaintLabels

public boolean getPaintLabels()
Returns:
true if labels are painted, else false
See Also:
setPaintLabels

setPaintLabels

public void setPaintLabels(boolean b)
Determines whether labels are painted on the slider.
See Also:
getPaintLabels

toString

public java.lang.String toString()
Returns a string containing that displays and identifies this object's propeties.
Overrides:
toString in class java.awt.Component

getAccessibleContext

public AccessibleContext getAccessibleContext()
Get the AccessibleContext associated with this JComponent
Specified by:
getAccessibleContext in interface Accessible
Returns:
the AccessibleContext of this JComponent
Overrides:
getAccessibleContext in class JComponent

Overview | Package | Class | Tree | Deprecated | Index | Help Java Platform
1.1.7
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Submit a bug or feature
Submit comments/suggestions about javadoc
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1998 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.